package com.rt.generalframework.web;

import com.rt.generalframework.dto.DictUsersDto;
import com.rt.generalframework.service.IDictUsersService;
import com.rt.generalframework.entity.DictUsers;
import com.rt.global.ErrorCode;
import com.rt.global.JsonResult;
import com.rt.util.JsonResultUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
  *
  *TODO(controller层代码示例).
  *
  *<p>TODO(注意所有参数统一用requestbody修饰).
  *
  *@return
  *@author 周昭名
  *@since 2019/9/23 12:52
*/
@RestController
@RequestMapping("/user")
@Slf4j
public class UserController {

    @Autowired
    IDictUsersService dictUsersService;
    /**
     * showdoc
     * @catalog 代码示例/用户模块
     * @title 用户列表(分页)
     * @description 分页查询用户列表
     * @method post
     * @url http://ip:端口/user/listPage
     * @json_param {"pageSize": "10","pageNo": "1"}
     * @param pageSize 必选 int 每页条数
     * @param pageNo 必选 int 当前第几页
     * @param name 可选 string 用户姓名（后模糊）
     * @param deptCode 可选 string 所属部门代码
     * @return {"status":"0","message":"操作成功","page":{"pageNo":1,"pageSize":2,"total":2352,"pages":1176},"result":[{"staffNo":"9618","name":"黄千群","deptCode":"0100","userId":"9618","password":"21232F297A57A5A743894A0E4A801FC3","createDate":"2012-03-23","sortNo":0,"publicFlag":"0"},{"staffNo":"9877","name":"陈元山","deptCode":"6000","userId":"9877","password":"202CB962AC59075B964B07152D234B70","inputCode":"cys","staffType":"3","createDate":"2012-03-23","sortNo":0,"publicFlag":"0","hospitalCode":"0001"}]}
     * @return_param status string 状态
     * @return_param message string 错误提示
     * @return_param staffNo string 用户流水号
     * @return_param name string 用户姓名
     * @return_param deptCode string 用户所属部门code
     * @return_param userId string 用户userId
     * @return_param password string 用户密码
     * @return_param createDate string 创建日期
     * @return_param sortNo string 排序号
     * @remark 这里是备注信息
     * @number 1
     */
    @RequestMapping("/listPage")
    public JsonResult getDictUsersByPage(@RequestBody DictUsersDto dto){
        JsonResult  jsonResult = dictUsersService.getDictUsersByPage(dto);
        return jsonResult;
    }

    /**
     * showdoc
     * @catalog 代码示例/用户模块
     * @title 用户列表
     * @description 查询用户列表
     * @method post
     * @url http://ip:端口/user/list
     * @json_param {"name": "张三","deptCode": "001"}
     * @param name 可选 string 用户姓名（后模糊）
     * @param deptCode 可选 string 所属部门代码
     * @return {"status":"0","message":"操作成功","result":[{"staffNo":"9618","name":"黄千群","deptCode":"0100","userId":"9618","password":"21232F297A57A5A743894A0E4A801FC3","createDate":"2012-03-23","sortNo":0,"publicFlag":"0"},{"staffNo":"9877","name":"陈元山","deptCode":"6000","userId":"9877","password":"202CB962AC59075B964B07152D234B70","inputCode":"cys","staffType":"3","createDate":"2012-03-23","sortNo":0,"publicFlag":"0","hospitalCode":"0001"}]}
     * @return_param status string 状态
     * @return_param message string 错误提示
     * @return_param staffNo string 用户流水号
     * @return_param name string 用户姓名
     * @return_param deptCode string 用户所属部门code
     * @return_param userId string 用户userId
     * @return_param password string 用户密码
     * @return_param createDate string 创建日期
     * @return_param sortNo string 排序号
     * @remark 这里是备注信息
     * @number 1
     */
    @RequestMapping("/list")
    public JsonResult getDictUsersAll(@RequestBody DictUsersDto dto){
        List<DictUsers> list = dictUsersService.getDictUsersAll(dto);
        JsonResult jsonResult = JsonResultUtil.success(ErrorCode.SUCCESS.value,list);
        return jsonResult;
    }
    /**
     * showdoc
     * @catalog 代码示例/用户模块
     * @title 删除用户
     * @description 根据主键删除用户
     * @method post
     * @url http://ip:端口/user/delete
     * @json_param {"staffNo": "001"}
     * @param staffNo 必选 string 用户流水号
     * @return {"status":"0","message":"删除成功"}
     * @return_param status string 状态
     * @return_param message string 错误提示
     * @remark 主键不能为空
     * @number 1
     */
    @RequestMapping("/delete")
    public JsonResult deleteDictUsersById(@RequestBody String staffNo){
        if(StringUtils.isBlank(staffNo)){
            log.error("staffNo不能为空！");
            return JsonResultUtil.failure("staffNo不能为空");
        }
        dictUsersService.deleteDictUsersByStaffNo(staffNo);
        return JsonResultUtil.success("删除成功！");
    }

    /**
     * showdoc
     * @catalog 代码示例/用户模块
     * @title 更新用户
     * @description 根据主键更新用户
     * @method post
     * @url http://ip:端口/user/update
     * @json_param {"staffNo": "001","name":"李四","deptCode":"1001"}
     * @param staffNo  必选 string 用户流水号
     * @param name  可选 string 用户姓名
     * @param deptCode  可选 string 用户所属部门code
     * @param userId  可选 string 用户userId
     * @param password  可选 string 用户密码
     * @param sortNo 可选 int 排序号
     * @return {"status":"0","message":"更新成功"}
     * @return_param status  string 状态
     * @return_param message  string 错误提示
     * @remark 主键不能为空
     * @number 1
     */
    @RequestMapping("/update")
    public JsonResult updateDictUsersByStaffNo(@RequestBody DictUsers dto){

        if(StringUtils.isBlank(dto.getStaffNo())){
            log.error("staffNo不能为空！");
            return JsonResultUtil.failure("staffNo不能为空");
        }
        dictUsersService.updateDictUsersByStaffNo(dto);
        return JsonResultUtil.success("更新成功");
    }



}